import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig(({ mode }) => {
  const isDev = mode === 'development'

  return {
    base: isDev ? '/' : '/server-api/gis/', // ✅ 开发是根路径，生产以服务路径开头
    plugins: [vue()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
    },
    server: {
      proxy: {
        '/server-api/gis': {
          target: 'http://localhost:8080', // ✅ 只代理主机和端口
          changeOrigin: true,
          // 不加 rewrite，保持路径一致
        },
      },
    },
    esbuild: {
      sourcemap: false,
    },
    build: {
      sourcemap: false,
      outDir: 'dist',
      emptyOutDir: true,
    },
  }
})
